using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using lucienneCRMApp.Models;

namespace lucienneCRMApp.Controllers
{   
    public class BookingsController : Controller
    {
        private lucienneCRMAppContext context = new lucienneCRMAppContext();

        //
        // GET: /Bookings/

        public ViewResult Index()
        {
            return View(context.Bookings.ToList());
        }

        //
        // GET: /Bookings/Details/5

        public ViewResult Details(int id)
        {
            Bookings bookings = context.Bookings.Single(x => x.BookingId == id);
            return View(bookings);
        }

        //
        // GET: /Bookings/Create

        public ActionResult Create()
        {
            
            return View();
        } 

        //
        // POST: /Bookings/Create

        [HttpPost]
        public ActionResult Create(Bookings bookings)
        {
            
                if (ModelState.IsValid)
                {
                    context.Bookings.Add(bookings);
                    context.SaveChanges();
                    return RedirectToAction("Index", "Home");
                }
              
                return View(bookings);
            
        }
        
        //
        // GET: /Bookings/Edit/5
 
        public ActionResult Edit(int id)
        {
            Bookings bookings = context.Bookings.Single(x => x.BookingId == id);
            return View(bookings);
        }

        //
        // POST: /Bookings/Edit/5

        [HttpPost]
        public ActionResult Edit(Bookings bookings)
        {
            if (ModelState.IsValid)
            {
                context.Entry(bookings).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(bookings);
        }

        //
        // GET: /Bookings/Delete/5
 
        public ActionResult Delete(int id)
        {
            Bookings bookings = context.Bookings.Single(x => x.BookingId == id);
            return View(bookings);
        }

        //
        // POST: /Bookings/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Bookings bookings = context.Bookings.Single(x => x.BookingId == id);
            context.Bookings.Remove(bookings);
            context.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                context.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}